package com.jz.community.moduleshopping.shopCart.model;

import android.support.annotation.NonNull;

import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.moduleshopping.shopCart.bean.CartGoodInfo;
import com.jz.community.moduleshopping.shopCart.bean.CartShopInfo;
import com.jz.community.moduleshopping.shopCart.bean.NewCartListInfo;

import java.util.List;

import static com.jz.community.moduleshopping.address.smarttop.utils.Lists.isEmpty;


/**
 * Created by Tony on 2018/5/18.
 * 购物车的一些状态分析
 */
public class ShoppingCartStatus {

    /**
     * 判断是否全部选中  ---
     * <p>
     *
     * @return
     */
    public boolean isAllSelectToEdit(List<CartShopInfo> goodsList) {
        return isAllSelect(goodsList);
    }

    /**
     * 判断 该列表中的购物车是否全部选中
     *
     * @param needToChooseList
     * @return
     */
    private boolean isAllSelect(List<CartShopInfo> needToChooseList) {
        if (Preconditions.isNullOrEmpty(needToChooseList)) {
            return false;
        }
        for (CartShopInfo item : needToChooseList) {
            for (CartGoodInfo cartInfosBean : item.getCartInfos()) {
                if (!ShopCartModel.CHECK.equals(cartInfosBean.getChecked())) {
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 判断是否至少有一个选中
     *
     * @return
     */
    public boolean hasLeastOneChoose(List<CartShopInfo> goodsList) {
        if (isEmpty(goodsList)) {
            return false;
        }
        List<CartShopInfo> shoppingList = goodsList;
        for (CartShopInfo shoppingItem : shoppingList) {
            for (CartGoodInfo cartInfosBean : shoppingItem.getCartInfos()) {
                if (isCheck(cartInfosBean)) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 判断是否选中
     *
     * @param item
     * @return
     */
    public boolean isCheck(@NonNull CartGoodInfo item) {
        Preconditions.checkNotNull(item);
        return ShopCartModel.CHECK.equals(item.getChecked());
    }
}
